package org.jeecg.modules.appuser.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.jeecg.common.api.vo.Result;
import org.jeecg.modules.appuser.entity.TbUserNoticeStatus;
import org.jeecg.modules.appuser.mapper.TbUserNoticeStatusMapper;
import org.jeecg.modules.appuser.service.ITbUserNoticeStatusService;
import org.springframework.stereotype.Service;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;

import java.util.List;

/**
 * @Description: 消息通知状态表
 * @Author: jeecg-boot
 * @Date: 2020-05-18
 * @Version: V1.0
 */
@Service
public class TbUserNoticeStatusServiceImpl extends ServiceImpl<TbUserNoticeStatusMapper, TbUserNoticeStatus> implements ITbUserNoticeStatusService {

    @Override
    public Result<?> updateUserNoticeState(TbUserNoticeStatus tbUserNoticeStatus) {
        QueryWrapper queryWrapper = new QueryWrapper();
        queryWrapper.eq("user_id", tbUserNoticeStatus.getUserId());
        List<TbUserNoticeStatus> tbUserNoticeStatusList = this.list(queryWrapper);
        if (null != tbUserNoticeStatusList && tbUserNoticeStatusList.size() > 0) {
            tbUserNoticeStatusList.forEach(tbUserNoticeStatus1 -> {
                tbUserNoticeStatus1.setState(1);
            });
            this.updateBatchById(tbUserNoticeStatusList);
        }
        return Result.ok("状态更新成功");
    }
}
